package com.asd.util;

public class PageBean {

	int total;     //总记录数
	int size = 10; // 默认每页10条
	int pages; // 总页
	int curPage; // 当前页
	// 起始，结束页码
	int beginNum;
	int endNum;

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
		pages = total / size;
		if (total % size !=0) {
			pages++;
		}
	}

	public int getBeginNum() {
		return beginNum;
	}

	public void setBeginNum(int beginNum) {
		this.beginNum = beginNum;
	}

	public int getEndNum() {
		return endNum;
	}

	public void setEndNum(int endNum) {
		this.endNum = endNum;
	}

	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}

	public int getPages() {
		return pages;
	}

	public void setPages(int pages) {
		this.pages = pages;
	}

	public int getCurPage() {
		return curPage;
	}

	public void setCurPage(int curPage) {
		this.curPage = curPage;
		if (pages <= 10) {
			beginNum = 1;
			endNum = pages;
		}else {
			beginNum = curPage -5;
			endNum =curPage + 4;
			if (beginNum <= 0) {// 头部溢出
				beginNum = 1;
				endNum = 10;
			}
			if (endNum > pages)// 尾部溢出
			{
				beginNum = pages - 9;
				endNum = pages;	 
			} 
		}
	}
	
	public void show() {
		System.out.println("总记录数" + total);
		System.out.println("总页数" + pages);
		System.out.println("当前页" + curPage);
		System.out.print("\n起始页" + beginNum);
		System.out.print("---结束页" + endNum);
	}

	public static void main(String[] args) {
		 PageBean pb = new PageBean();
		 pb.setTotal(188);  // 188篇文章
		 pb.setCurPage(18);		 
		 pb.show();
	}
}
